package net.fpeg.kotlin.msa.wordbase.service

import net.fpeg.kotlin.msa.wordbase.dao.WordDao
import net.fpeg.kotlin.msa.wordbase.entity.Word
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service

@Service
class WordService {

    @Autowired
    lateinit var wordDao: WordDao

    fun get(value: String) = wordDao.getByValue(value)
    fun getOne(value: String) = get(value) ?: throw Exception("单词不存在")

    fun add(value: String) = get(value) ?: wordDao.save(Word(
            value = value
    ))


}